//
//  TeamViewController.m
//  WE
//
//  Created by iMacOne on 15/11/19.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "TeamViewController.h"
#import "Head.h"
#import "DoctorViewController.h"
#import "AuthenticateControl.h"
#import "EMMallSectionView.h"
@interface TeamViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * bottomView;
@property (nonatomic, strong)UIButton * contentBtn;
@property (nonatomic, strong)UIImageView * arrowImage;
@property (nonatomic, assign)BOOL isOpen;

@end

@implementation TeamViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"专家团队";

    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    [self creatBottomBtn];
    self.isOpen = NO;
//    [self setExtraCellLineHidden:self.tableView];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}

- (void)creatBottomBtn
{
    self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, WindowHeight - 60, WindowWidth, 60)];
    _bottomView.userInteractionEnabled = YES;
    _bottomView.backgroundColor = [UIColor whiteColor];
    UILabel * bottomLbl = [[UILabel alloc] initWithFrame:CGRectMake(margin_10, margin_10, WindowWidth - 90, 40)];
    bottomLbl.text = @"专家团队将根据您的病情分配医生进行初诊, 享受专家远程会诊和优先转诊等服务.";
    bottomLbl.font = FONT(12);
    bottomLbl.textColor = CONTENTCOLOR;
    bottomLbl.numberOfLines = 0;
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake( CGRectGetMaxX(bottomLbl.frame) + margin_10 ,5, 60, 50);
//            btn.layer.borderWidth = 0.5;
            [btn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
//            btn.layer.borderColor = [UIColor grayColor].CGColor;
            btn.backgroundColor = [UIColor orangeColor];
    btn.layer.masksToBounds = YES;
    btn.layer.cornerRadius = 5;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"对症预约" forState:UIControlStateNormal];
    btn.titleLabel.font = FONT(12);
    
    [ToolUtil createLine:0 superView:_bottomView lift:0 width:WindowWidth hight:1 color:GRAYCOLOR];
    [self.bottomView addSubview:bottomLbl];
    [self.bottomView addSubview:btn];
    [self.view addSubview:self.bottomView];
}
- (void)clickbtn:(UIButton *)btn
{
    [self.navigationController pushViewController:[[AuthenticateControl alloc] init] animated:YES];
    
}
- (UIView *)creatHeaderView
{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 64, WindowWidth, 100)];
    UIImageView * aImgeView = [[UIImageView alloc] initWithFrame:CGRectMake(margin_10 * Width, margin_10 * Height, margin_30* Width , margin_30* Width)];
    aImgeView.layer.masksToBounds = YES;
    aImgeView.layer.cornerRadius = 15*Width;
    aImgeView.backgroundColor = DEBUG_CLOLR;
    
    UILabel * nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(aImgeView.frame) + margin_10, aImgeView.frame.origin.y, margin_90, margin_15)];
    nameLbl.font = FONT(12);
    nameLbl.text = @"警惕的专家团队";
    
    UILabel * idenLbl = [[UILabel alloc] initWithFrame:CGRectMake(aImgeView.frame.origin.x, CGRectGetMaxY(aImgeView.frame) + 3 , WindowWidth - 20, [ToolUtil customAutoHeigh:@"副主治医生前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的" width:WindowWidth - 20 num:10])];
    idenLbl.font = FONT(10);
    
    idenLbl.numberOfLines = 3;
    idenLbl.text = @"副主治医生前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的副主治医生前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的";
    self.contentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _contentBtn.frame = CGRectMake(WindowWidth - 40, CGRectGetMaxY(idenLbl.frame)+3, 30, 30);
    [_contentBtn addTarget:self action:@selector(doClickButton:) forControlEvents:UIControlEventTouchUpInside];
    int icon_w = 40 * 0.4, icon_h = 40*0.4*0.63, icon_x = (40 - icon_w) / 2, icon_y = (30 - icon_h) / 2;
    self.arrowImage = [[UIImageView alloc] initWithFrame:CGRectMake(icon_x, icon_y , icon_w, icon_h)];
    if (!self.isOpen) {
        self.arrowImage.image = [UIImage imageNamed:@"arrow_bottom.png"];
        
        
    }else if (self.isOpen){
        self.arrowImage.image = [UIImage imageNamed:@"arrow_up.png"];
        idenLbl.numberOfLines = 0;
        idenLbl.frame = CGRectMake(aImgeView.frame.origin.x, CGRectGetMaxY(aImgeView.frame) + 3 , WindowWidth - 20, [ToolUtil customAutoHeigh:@"副主治医生前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的副主治医生前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的 <<医馆笑谈>> 中前段时间播出的" width:WindowWidth - 20 num:10]);
    }
    
    [_contentBtn addSubview:_arrowImage];
    [view addSubview:aImgeView];
    [view addSubview:nameLbl];
    [view addSubview:idenLbl];
    [view addSubview:_contentBtn];
    return view;
}
- (void)doClickButton:(UIButton *)btn
{
    if (!self.isOpen) {
        self.isOpen = YES;
        self.arrowImage.image = [UIImage imageNamed:@"arrow_up.png"];
    }else if (self.isOpen){
        self.arrowImage.image = [UIImage imageNamed:@"arrow_bottom.png"];
        self.isOpen = NO;
        
    }
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
}


- (UITableView *)tableView
{
    if (_tableView == nil) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0 ,WindowWidth , WindowHeight - 60 ) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
//        _tableView.rowHeight = 90;
        _tableView.showsVerticalScrollIndicator = NO;

//        _tableView.scrollEnabled = NO;
    }
    return _tableView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2 && indexPath.row == 0) {
        return 30;
    }
    return 90;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0 ) {
        return 0;
    }else if (section == 1){
        return 1;
    }else if (section == 2){
        return 2;
    }
    return 5;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return [self creatHeaderView];
    }else if (section == 2){
       
        EMMallSectionView *sectionView =  [EMMallSectionView showWithName:nil];
        sectionView.sign = @"1";
        sectionView.tableView = self.tableView;
        sectionView.section = section;
        return sectionView;

    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 110;
    }else if (section == 2){
        return 10;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if (indexPath.section == 0) {
//        
//    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        TeamDetailCell * cell = [[TeamDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.specialLbl.hidden = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }else if (indexPath.section == 2 && indexPath.row == 0){
        UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.textLabel.text = @"团队成员";
        cell.textLabel.font = FONT(14);
        cell.textLabel.textColor = CONTENTCOLOR;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    static NSString * cellIdentifier = @"Teamcell";
    TeamDetailCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[TeamDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
//        cell.titleLbl.text = _array[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.specialLbl.hidden = YES;
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    DoctorViewController * doctVC = [[DoctorViewController alloc] init];
    [self.navigationController pushViewController:doctVC animated:YES];
    
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
//-(void)setExtraCellLineHidden: (UITableView *)tableView
//{
//    UIView *coverView = [UIView new];
//    tableView.tableFooterView = coverView;
//}



@end
